<template>
  <div id="blog-right">
    <div class="c-right">
      <ul>
        <li>
          <Tabs value="name2">
            <TabPane label="博主推荐" name="name2">
              <Carousel autoplay v-model="value1"
                        :autoplay-speed="speed"
                        loop>
                <div style="text-align: left" :key="index"   v-if="recommendeds.length>0"
                     v-for="(recommended,index) in recommendeds">
                  <CarouselItem>
                    <div class="demo-carousel" @click="showDetail(recommended.id)"><img :src="recommended.images">
                    </div>
                  </CarouselItem>
                </div>
              </Carousel>
            </TabPane>
          </Tabs>
        </li>
        <li class="one">
          <Tabs value="name1">
            <TabPane label="阅读排行" name="name1">
              <div style="text-align: left" :key="index" v-if="reads!=null" v-for="(read,index) in reads">
                <a @click="showDetail(read.id)">
                  <div class="readtitle">
                    <b :class="_getRankCls(index)">{{_getRankText(index)}}</b> <span>{{read.title}}</span>
                  </div>
                </a>
              </div>
            </TabPane>
          </Tabs>
        </li>

        <!--        <li class="two">-->
        <!--          <Tabs value="name1">-->
        <!--            <TabPane label="标签" name="name1">-->
        <!--              <span :key="index" v-for="(la,index) in reads">-->
        <!--                    <Tag @click.native="showTagArticle(la.title)" :name="la.title"-->
        <!--                         :style="RandomColor()">{{la.title}}</Tag>-->
        <!--                </span>-->
        <!--            </TabPane>-->
        <!--          </Tabs>-->
        <!--        </li>-->

        <li class="three">
          <Tabs value="name1">
            <TabPane label="关于我" name="name1">
              <div class="aboutme">
                <h2 class="ab_title">关于我</h2>
                <div class="avatar">
                  <img
                    src="../../assets/touxiang.jpg">
                </div>
                <div class="ab_con">
                  <p>姓名：fuzhaofang</p>
                  <p>职业：java工程师</p>
                  <p>gitee：<a target="_blank" href="">一枚码农</a></p>
                  <p>github:<a target="_blank" href="">fc8edu</a></p>
                  <p>开源项目:<a target="_blank" href="">fc8edu</a></p>
                </div>
                <div class="linkmore">
                  <ul>
                    <li><a href="https://shop279575310.taobao.com" target="_blank" class="iconfont icon-taobao"
                           title="淘宝店铺"></a></li>
                    <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=2532540336@qq.com"
                           target="_blank" class="iconfont icon-email" title="我的邮箱"></a></li>
                    <li><a href="http://wpa.qq.com/msgrd?v=3&amp;uin=2532540336&amp;site=qq&amp;menu=yes"
                           target="_blank"
                           class="iconfont icon-QQ" title="QQ联系我"></a></li>
                    <li class="weixin" @mouseenter="enter" @mouseleave="leave"><a class="iconfont icon-iconwx"
                                                                                  title="关注我的微信"></a>
                      <i v-show="seen"><img src="../../assets/wx.jpg"></i>
                    </li>
                  </ul>
                </div>
              </div>
            </TabPane>
          </Tabs>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
  export default {
    name: "blog-right",
    data() {
      return {
        value1: 1,
        speed: 4000,
        label: {},
        checkable: true,
        recommendeds: [],
        reads: [],
        seen: false
      }
    },
    methods: {
      RandomColor() {
        let r, g, b;
        r = Math.floor(Math.random() * 256);
        g = Math.floor(Math.random() * 256);
        b = Math.floor(Math.random() * 256);
        return {
          height: '40px',
          width: '80px', // 进度条
          background: 'rgb(' + r + ',' + g + ',' + b + ')'
        };

      },
      _getRankCls(index) {
        if (index < 3) {
          return 'songlist-rank icon' + index
        }
        return 'songlist-rank'	//后面的样式是文字样式
      },
      //添加文字的方法
      _getRankText(index) {
        return index + 1
      },


      enter: function () {
        this.seen = true;

      },
      leave: function () {
        this.seen = false;

      },

      start() {
        this.$Loading.start();
      },
      finish() {
        this.$Loading.finish();
      },
      error() {
        this.$Loading.error();
      },
      init() {
        this.getRecommended();
        this.getOrderArticle();
      },
      videoDetail(code) {
        this.$router.push(`/videoDetail/${code}`)
      },
      showTagArticle(name) {
        this.$router.push({path: `/tag/${name}`});
      },
      getRecommended() {
        this.$http.get("/api/blog/recommended").then(res => {
          this.recommendeds = res.data.data;
        }).catch(error => {
          this.$Message.error('获取推荐失败');
        })
      },
      getOrderArticle() {
        this.$http.get('/api/blog/read/order').then(res => {
          this.reads = res.data.data;
        }).catch(error => {
          this.$Message.error('获取阅读排行失败');
        })
      },
      showDetail(code) {
        this.$router.push({path: `/detail/${code}`});
      }
    },
    mounted() {
      this.init();
    },
    created(){
      this.init();
    }
  }
</script>

<style scoped>
  .readtitle {
    color: #5A5B5E;
    height: 25px;
    width: 98%;
    margin: 2px 0 0 5%;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }

  .aboutme {
    background: #FFF;
    border-radius: 10px;
    overflow: hidden;
  }

  .ab_title {
    text-align: center;
    position: relative;
    margin: 20px;
  }

  .ab_title:before {
    content: "";
    width: 25%;
    height: 2px;
    background: #000;
    position: absolute;
    left: 0;
    bottom: 8px;
  }

  .ab_title:after {
    content: "";
    width: 25%;
    height: 2px;
    background: #000;
    position: absolute;
    right: 0;
    bottom: 8px;
  }

  .avatar {
    width: 100px;
    height: 100px;
    overflow: hidden;
    border-radius: 50px;
    margin: auto;
  }

  .avatar img {
    width: 100px;
    height: 100px;
  }

  img {
    border: 0;
    display: block;
  }

  .ab_con {
    line-height: 30px;
    padding: 10px;
  }

  .demo-carousel {
    width: 100%;
    max-height: 220px;
    line-height: 220px;
    text-align: center;
    color: #fff;
    font-size: 20px;
    background: #fff;
  }

  .demo-carousel img {
    width: 99%;
    max-height: 220px;
  }

  .c-right {
    width: 35%;
    height: auto;
    float: right;
  }

  .c-right ul li {
    list-style: none;
    width: 100%;
    height: auto;
    min-height: 200px;
    background: #fff;
    border: 0px solid red;
    margin-top: 10px;
  }

  .linkmore {
    margin: 15px;
  }

  .linkmore ul li {
    list-style: none;
    width: 25%;
    float: left;
  }

  .linkmore ul li a {
    height: 45px;
    display: block;
    overflow: hidden;
    box-shadow: 0px 1px 0px rgba(255, 255, 255, .1), inset 0px 1px 1px rgba(0, 0, 0, .7);
    border-radius: 50%;
    margin: 0 5px;
  }


  .weixin {
    position: relative
  }

  .weixin i {
    display: block;
    position: absolute;
    bottom: 180px;
    right: 80px;
  }

  .weixin i img {
    width: 150px;
    height: 150px;
  }

  .songlist-rank {
    display: inline-block;
    vertical-align: middle;
    *vertical-align: auto;
    *display: inline;
    zoom: 1;
    width: 20px;
    height: 20px;
    background: #ddd;
    color: #1d1d1d;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    line-height: 20px;
    margin-right: 10px;
  }

  .icon0 {
    background: #FF3030;
    color: #1d1d1d;
  }

  .icon1 {
    background: #fd0;
    color: #1d1d1d;
  }

  .icon2 {
    background: #fd0;
    color: #1d1d1d;
  }


  @media screen and (max-width: 768px) {
    .c-right {
      width: 100%;
      height: auto;
      float: right;
    }

    .c-right ul li {
      width: 100%;
      height: auto;
      background: #fff;
      margin-top: 10px;
    }

    .linkmore {
      margin: 1px;
    }

    .linkmore ul li {
      list-style: none;
      width: 24.5%;
      float: left;
    }

    .linkmore ul li a {
      height: 45px;
      display: block;
      overflow: hidden;
      box-shadow: 0px 1px 0px rgba(255, 255, 255, .1), inset 0px 1px 1px rgba(0, 0, 0, .7);
      border-radius: 50%;
      margin: 0 5px;
    }

    .demo-carousel {
      height: 140px;
      line-height: 140px;
      text-align: center;
      color: #fff;
      font-size: 20px;
      background: #fff;
    }

    .demo-carousel img {
      width: 300px;
      height: auto;
    }


    .weixin {
      position: relative
    }

    .weixin i {
      display: block;
      position: absolute;
      bottom: 80px;
      right: 40px;
    }

    .weixin i img {
      width: 150px;
      height: 150px;
    }


  }
</style>
